package hr.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import hr.entity.DO.EmployeeMovementDO;
import hr.entity.Employee;
import hr.entity.vo.EmployeeMovementVo;
import hr.service.EmployeemovementService;
import hr.utils.Result.R;
import hr.utils.Result.Result;
import hr.utils.Result.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 员工调动记录表 前端控制器
 * </p>
 *
 * @author zzh
 * @since 2023-12-14
 */
@Tag(name = "员工调动记录表")
@RestController
@RequestMapping("/employeemovement")
public class EmployeemovementController {
    @Autowired
    private EmployeemovementService employeemovementService;

    @Operation(summary = "岗位调动记录")
    @PostMapping("/getEmployeeMovement")
    public Result<Object> getEmployeeMovement(@RequestBody EmployeeMovementVo vo) {
        HashMap<String, Object> map = new HashMap<>();
        List<EmployeeMovementDO> list = employeemovementService.getEmployeeMovement(vo);
        map.put("list", list);
        IPage<Employee> pageInfo = new Page<>(vo.getPage(), vo.getLimit());
        Integer count = employeemovementService.getCount(vo);
        map.put("count", count);
        map.put("pageInfo", pageInfo);
        return ResultUtil.success(map);
    }

    @Operation(summary = "获取员工调动记录")
    @PostMapping("/getEmployeeMovementByEmpId")
    public R getEmployeeMovementByEmpId(@RequestBody EmployeeMovementDO vo) {

        List<EmployeeMovementDO> list = employeemovementService.getEmployeeMovementByEmpId(vo.getEmployeeId());
        return R.success().addKeyValueToData("list",list);
    }

    @Operation(summary = "部门岗位调动")
    @PostMapping("/departmentPostMovement")
    public Result<Object> departmentPostMovement(@RequestBody EmployeeMovementDO movementDO) {
        return employeemovementService.updateDepartmentPostMovement(movementDO) ? ResultUtil.success("调动成功") : ResultUtil.fail("调动失败");
    }

}
